|
|
|
|
|
|
|
If you want to create an array of the type Variant, you can declare the array explicitly, as you just learned, or you can use the Array function. Consider the following code: |
|
|
|
 |
|
|
|
|
Dim vntEmployees As Variant
vntNames = Array("Paul", "Ken", "Bill", "Tom")
Me.Print vntNames(0)
Me.Print vntNames(1)
Me.Print vntNames(2)
Me.Print vntNames(3) |
|
|
|
|
|
|
|
|
This code declares a Variant variable thats Empty. The Array function is then called. It takes all the parameters passed to it, creates an array, and passes that array back the variant. Because a variant can have any value in it, the array thats passed back is perfectly valid in this case. You can now access the array as normal. |
|
|
|
|
|
|
|
|
By looking at the variable name, vntNames, in the previous example, you cant tell what kind of data is in the variant variable. However, you can use the IsArray() function to determine whether the data in a variant is an array: |
|
|
|
 |
|
|
|
|
boolArray = IsArray(vntName) |
|
|
|
|
|
|
|
|
The IsArray() function will return True if the value in the vntName variable is an array. It will return False if the value is not an array. |
|
|
|
|
|
|
|
|
Visual Basic will not allow you to overrun an arrays boundaries. If you declare an array as a five-element array, you cannot access element 10. If you try to access this element, youll get a runtime error from Visual Basic. In order to ensure that this does not happen, Visual Basic includes a couple of functions that you can use to get the lower and the upper bounds of an array. |
|
|
|
|
|